package com.youmans.eduOrder.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.youmans.commonutils.orderVo.CourseWebVoOrder;
import com.youmans.commonutils.orderVo.UcenterMember;
import com.youmans.eduOrder.client.EduClient;
import com.youmans.eduOrder.client.UcenterClient;
import com.youmans.eduOrder.entity.Order;
import com.youmans.eduOrder.mapper.OrderMapper;
import com.youmans.eduOrder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author Youmans
 * @since 2022-05-22
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private EduClient eduClient ;

    @Autowired
    private UcenterClient ucenterClient ;
    @Override
    public String createOrders(String courseId, String memberIdByJwtToken) {
        UcenterMember userInfoOrder = ucenterClient.getUserInfoOrder(memberIdByJwtToken);
        CourseWebVoOrder courseDto = eduClient.getCourseInfoOrder(courseId);
//        创建Order 对象，设置数据
        Order order = new Order();
        order.setOrderNo(IdWorker.getIdStr()) ;
        order.setCourseId(courseId);
        order.setCourseTitle(courseDto.getTitle());
        order.setCourseCover(courseDto.getCover());
        order.setTeacherName (courseDto.getTeacherName());
        order.setTotalFee(courseDto.getPrice());
        order.setMemberId(memberIdByJwtToken);
        order.setMobile(userInfoOrder.getMobile());
        order.setNickname(userInfoOrder.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
